package com.taijia.chapter8;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * TestBufferStream1
 * 
 * @author taijia
 * @since 2014年11月25日
 *
 */
public class TestBufferStream1 {

	public static void main(String[] args) {
		InputStream fis = null;
		BufferedInputStream bis = null;
		try {
			fis = new FileInputStream("E:/myeclipse2014/Workspaces/2014/msb_basic/src/com/taijia/chapter8/TestBufferStream1.java");
			bis = new BufferedInputStream(fis);
			int c = 0;
			System.out.print((char) bis.read());
			System.out.print((char) bis.read());
			System.out.println(" === ");
			bis.mark(100);
			for (int i = 0; (i < 29 && (c = bis.read()) != -1); i++) {
				System.out.print((char)c + " ");
			}
			bis.reset();
			System.out.println(" === ");
			for (int i = 0; (i < 29 && (c = bis.read())!= -1); i++) {
				System.out.print(c + " "); // 注意 13 10 是回车 换行符
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.exit(-1);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(-1);
		} finally {
			try {
				fis.close();
				bis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
